Exercises

Exercise 1

Add title and labels for the x and y axis to Lab3 ex1. Color the bars blue

library(ggplot2)
library(tidyverse)
## -- Attaching packages --------------------------------------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v tibble  2.1.3     v dplyr   0.8.3
## v tidyr   1.0.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.4.0
## v purrr   0.3.3
## -- Conflicts ------------------------------------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
SNPs<- read.table("C:/Users/Zhaozhen Luo/Desktop/2020 spring/bio 497/lab 2/23andMe_complete.txt", header = TRUE, sep = "\t")

chromosome<- ggplot(SNPs, aes(chromosome))
plot_1_1_<- chromosome+geom_bar()

plot_1_2_<- plot_1_1_ + ggtitle("total SNP counts \nof for each chromosome") + labs(y="number of SNPs in each chromosome", x = "chromosome") + geom_bar(fill='steelblue')

plot_1_2_

Exercise 2

To Lab3 ex3 add more defined x and y axis labels, add a title, Change the colors of the genotypes, so that the dinucleotides (e.g. AA) are one color, the mononucleotides (A) are another and D’s and I’s a third color. One way to do this is to specify the color of each genotype.

plot_2_1_<-chromosome + geom_bar(aes(fill=genotype))

plot_2_2_<- plot_2_1_ + scale_fill_manual(values = c("orange", "black", "orange", "orange", "orange", "orange", "black", "orange", "orange", "orange", "green", "green", "orange", "black", "orange", "orange", "green", "green", "black", "orange", "black", "orange", "orange", "black", "orange")) +
ggtitle("Count of Chromosome") + xlab("Chromosome") + ylab("Frequency")

plot_2_2_

Exercise 3

From Lab3 ex5, make an output png file, then load the file into report using the RMarkdown or html format.

Genotype for each chromosome

Exercise 4

For Lab3 ex6 add more defined x and y axis labels, add a title, make the x-axis for each graph readable in your final report file.

plot_4_1_<- chromosome + geom_bar(aes(fill = genotype), position = "dodge") + facet_wrap(~chromosome + genotype)

plot_4_2_<- plot_4_1_ + facet_wrap(~chromosome, scales = "free_x")+ ggtitle("Genotype Contributions of Chromosomes") + xlab("Genotype") + ylab("number of SNPs")

plot_4_2_

Exercise 5

Turn Lab3 ex6 into an interactive graph using plotly

library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
table_5_<- ggplotly(
  chromosome + geom_bar(aes(fill = genotype), position = "dodge") + facet_wrap(~chromosome + genotype))
 
table_5_

Exercise 6

Make an interactive table of the SNPS found in on the Y chromosome from the 23andMe_complete data set

library(DT)

data_6_ <-subset(SNPs, chromosome=="Y")

datatable(data_6_)
## Warning in instance$preRenderHook(instance): It seems your data is too big
## for client-side DataTables. You may consider server-side processing: https://
## rstudio.github.io/DT/server.html